using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

/// <summary>
/// 存档系统
/// </summary>
public class SaveSystem : AbstractSystem
{
    private HashSet<string> keys = new HashSet<string>();    // 拦截

    public void Save()
    {

    }

    public void Load()
    {

    }

    public void SaveBool(string key, bool value)
    {
        keys.Add(key);
        PlayerPrefs.SetInt(key, value ? 1 : 0);
    }

    public bool LoadBool(string key, bool defaultValue = false)
    {
        keys.Add(key);
        return PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
    }

    public void SaveInt(string key, int value)
    {
        keys.Add(key);
        PlayerPrefs.SetInt(key, value);
    }

    public int LoadInt(string key, int defaultValue = 0)
    {
        keys.Add(key);
        return PlayerPrefs.GetInt(key, defaultValue);
    }

    public void SaveString(string key, string value)
    {
        keys.Add(key);
        PlayerPrefs.SetString(key, value);
    }

    public string LoadString(string key, string defaultValue = default)
    {
        keys.Add(key);
        return PlayerPrefs.GetString(key, defaultValue);
    }

    protected override void OnInit()
    {
        ActionKit.OnGUI.Register(() =>
        {
            if(Input.GetKey(KeyCode.L))
            {
                foreach (var key in keys)
                {
                    GUILayout.Label(key + ":" + PlayerPrefs.GetInt(key));
                    GUILayout.Label(key + ":" + PlayerPrefs.GetFloat(key));
                    GUILayout.Label(key + ":" + PlayerPrefs.GetString(key));
                }
            }
        });
    }
}
